package com.shujia.zookeeper;

import org.apache.zookeeper.*;

import java.io.IOException;

public class Code02CreateNode {
    public static void main(String[] args) throws IOException, InterruptedException, KeeperException {

        ZooKeeper zooKeeper = new ZooKeeper("master:2181,node1:2181,node2:2181",
                15 * 1000,
                new Watcher() {
                    @Override
                    public void process(WatchedEvent event) {
                        System.out.println("process函数执行了...");
                    }
                }
        );

        // public String create(final String path, byte data[], List<ACL> acl,
        //            CreateMode createMode)
        zooKeeper.create(
                "/api",
                "api data".getBytes(),
                ZooDefs.Ids.OPEN_ACL_UNSAFE,
                CreateMode.PERSISTENT // 表示创建一个持久化的节点（普通节点）
        );

        zooKeeper.close();
    }
}
